package xyz.hubery.controller;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import xyz.hubery.domain.CoinRecharge;
import xyz.hubery.domain.CoinWithdraw;
import xyz.hubery.model.R;
import xyz.hubery.service.CoinWithdrawService;

@RestController
@RequestMapping("/coinWithdraws")
@Api("提币记录")
public class CoinWithdrawController {

    @Autowired
    private CoinWithdrawService coinWithdrawService;
    @Autowired
    private CoinRechargeController coinRechargeController;

    @GetMapping("/records")
    @ApiOperation("分页查询提币记录")
    public R<Page<CoinWithdraw>> findByPage(Long userId,
                                            String userName,
                                            String mobile,
                                            Byte status,
                                            Integer numMin,
                                            Integer numMax,
                                            String startTime,
                                            String endTime
            , Page<CoinWithdraw> page) {
        Page<CoinWithdraw> coinWithdrawPage = coinWithdrawService.findPage(userId, userName, mobile, status, numMin, numMax, startTime, endTime,  page);
        return R.ok(coinWithdrawPage);
    }

    @GetMapping("/user/record")
    public R<Page<CoinWithdraw>> findUserPage(@RequestParam(required = false) Long coinId,Page<CoinWithdraw> page) {
        Long userId = Long.valueOf(SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString());
        page.addOrder(OrderItem.desc("last_update_time"));
        Page<CoinWithdraw> pageData =  coinWithdrawService.findUserPage(userId, coinId, page);
        return R.ok(pageData);
    }



}
